package com.wwdx.service.impl;

import com.google.common.collect.Maps;
import com.wwdx.model.WwdxCouponModel;
import com.wwdx.service.WwdxCouponServiceI;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author liguoliang
 * @date 2018/4/20 14:50
 */
@Service
public class WwdxCouponServiceImpl extends BaseServiceImpl<WwdxCouponModel> implements WwdxCouponServiceI {

    @Override
    public Long selectModelCount(WwdxCouponModel model) {
        Map<String, Object> params = Maps.newHashMapWithExpectedSize(4);
        String hql = "select count(1) from WwdxCouponModel\t"+getParams(model,params);
        return count(hql,params);
    }

    private String getParams(WwdxCouponModel model, Map<String, Object> params){
        StringBuilder sb = new StringBuilder("where 1=1\n");
        return sb.toString();
    }

    @Override
    public List<WwdxCouponModel> selectModelList(WwdxCouponModel model, Integer page, Integer rows) {
        Map<String, Object> params = Maps.newHashMapWithExpectedSize(4);
        String hql = "from WwdxCouponModel\t"+getParams(model,params)+"\torder by gmtCreated desc";
        return find(hql, params, page, rows);
    }

    @Override
    public List<WwdxCouponModel> list() {
        return find("from WwdxCouponModel where status = 0 and DATEDIFF(expires,CURDATE())>=0");
    }
}